package homework02;

import java.util.Random;

public class RockPaperScissors {
    private String computerchoice;

    public RockPaperScissors() {
        generateComputerChoice();
    }

    public void generateComputerChoice(){
        Random random = new Random();
        int choice = random.nextInt(3);
        switch (choice){
            case 0:
                computerchoice = "石头";
                break;
            case 1:
                computerchoice = "剪刀";
                break;
            case 2:
                computerchoice = "布";
                break;
        }
    }

    public String getComputerchoice() {
        return computerchoice;
    }

    public String judge(String userchoice){
        if (userchoice.equals(computerchoice)) {
            return "平局!";
        }
        switch(userchoice){
            case "石头":
                return (computerchoice.equals("剪刀")) ? "你赢了!" : "你输了";
            case "剪刀":
                return (computerchoice.equals("布")) ? "你赢了!" : "你输了";
            case "布":
                return (computerchoice.equals("石头")) ? "你赢了!" : "你输了";
        }
        return "无效的用户输入";
    }
}
